#include <cstdio>

const int N = 10005;
int n, m;
int fa[N];

int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("UnionFindSet.in", "r", stdin);
  freopen("UnionFindSet.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    fa[i] = i;
  }
  int x, y, opt;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &opt, &x, &y);
    if (opt == 1) {
      fa[find(x)] = find(y);
    } else {
      printf(find(x) == find(y) ? "Y\n" : "N\n");
    }
  }
  return 0;
}